import { useState, useMemo, FC } from 'react';
import Child from './components/Child';

const Index: FC = () => {
  const [count, setCount] = useState<number>(5);
  const [list, setList] = useState<number[]>([1, 2, 3, 4, 5, 6, 7]);

  const add: () => void = (): void => {
    setCount((v: number) => v + 1);
  };

  const oddList = useMemo<number[]>(() => {
    return list.filter((item: number) => item % 2);
  }, [list]);

  const minus = (num: number): void => {
    setCount((v: number) => (v -= num));
  };

  return (
    <>
      <h2>ts</h2>
      <button onClick={() => minus(2)}>-</button>
      <span>{count}</span>
      <button onClick={add}>+</button>

      <ul>
        {oddList.map((item) => {
          return <li key={item}>{item}</li>;
        })}
      </ul>

      <Child count={count} />
    </>
  );
};

export default Index;
